package com.szt.school.mapper;

import com.szt.school.pojo.GoodsType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
* 当我们使用接口的方式开发mybatis的接口时
* 就不需要再去创建Mapper.xml等文件
* 直接将sql语句放到对应方法中*/
@Repository
@Mapper
public interface GoodsTypeMapper {
    @Select(value = "select * from goods_type where goods_type_id " + "= #{goodsTypeId, jdbcType=INTEGER}")
    @Results
//    @Results(value = {
//            @Result(column = "goods_type_id", property =
//                    "goodsTypeId", jdbcType = JdbcType.INTEGER),
//            @Result(column = "goods_type_name", property ="goodsTypeName", jdbcType = JdbcType.VARCHAR)})
    GoodsType selectOne(Integer Id);

    @Insert(value = "insert into goods_type(goods_type_id, goods_type_name) " + "values(#{goodsTypeId, jdbcType=INTEGER},"
        + "#{goodsTypeName, jdbcType=VARCHAR})")
        void insertOne(GoodsType goodsType);

    @Update(value = "update goods_type set goods_type_name = #{goodsTypeName, jdbcType=VARCHAR} " +
            "where goods_type_id = #{goodsTypeId, jdbcType=INTEGER}")
        void updateOne(GoodsType goodsType);

    @Delete(value = "delete from goods_type where goods_type_id " + "= #{goodsTypeId, jdbcType=INTEGER}")
    void deleteById(Integer goodsTypeId);

    @Select("select * from goods_type")
    @Results(value = {
            @Result(column = "goods_type_id", property =
                    "goodsTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "goods_type_name", property =
                    "goodsTypeName", jdbcType = JdbcType.VARCHAR)
    })
    List<GoodsType> selectAll();
}

